/* nixonFTP
 * FTP client version 0.1
 * Copyright (C) 2010 NIXON Development Corporation.
 * All rights reserved.
 * http://members.shaw.ca/nixon.com
*/

package nixonftp.ui;

import nixonftp.*;
import java.util.HashMap;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

/**
 *
 * @author Billy
 */
public class NXFtpMenu extends JPopupMenu {
	private HashMap menuItems = new HashMap();
	private HashMap separators = new HashMap();
	private JMenu deleteMenu;
	public JMenuItem switchView;
	public boolean local;
	
	public NXFtpMenu(boolean local) {
		super();
		this.local = local;
		NXMenuItem menuItem;
		String s;

		ClassLoader cldr = this.getClass().getClassLoader();
		ImageIcon folderIcon = new ImageIcon(cldr.getResource("icons/addfolder.gif"));

		String transferIconFile;
		if (local) transferIconFile = "icons/upload.png";
		else transferIconFile = "icons/download.png";
		ImageIcon transferIcon = new ImageIcon(cldr.getResource(transferIconFile));
		ImageIcon deleteIcon = new ImageIcon(cldr.getResource("icons/trash.png"));

		s = "NewFolderIn";
		menuItem = new NXMenuItem("New folder in ", s);
		menuItem.setIcon(folderIcon);
		menuItems.put(s, menuItem);
		add(menuItem);

		s = "NewFolder";
		menuItem = new NXMenuItem("New folder", s);
		menuItem.setIcon(folderIcon);
		menuItems.put(s, menuItem);
		add(menuItem);

		JSeparator topSeparator = new JSeparator(SwingConstants.HORIZONTAL);
		add(topSeparator);
		separators.put("top", topSeparator);

		s = "Reload";
		menuItem = new NXMenuItem("Reload", s);
		menuItems.put(s, menuItem);
		add(menuItem);

		s = "SwitchView";
		menuItem = new NXMenuItem("Detailed View", s);
		menuItem.setIcon(NXIcon.detail);
		menuItems.put(s, menuItem);
		switchView = menuItem;
		add(menuItem);

		JSeparator middleSeparator = new JSeparator(SwingConstants.HORIZONTAL);
		add(middleSeparator);
		separators.put("middle", middleSeparator);

		s = "Rename";
		menuItem = new NXMenuItem("Rename", s);
		menuItems.put(s, menuItem);
		add(menuItem);

		s = "Delete";
		deleteMenu = new JMenu("Delete");
		deleteMenu.setIcon(deleteIcon);
		menuItem = new NXMenuItem("Delete", s);
		menuItem.setActionCommand("Delete");
		menuItem.setIcon(deleteIcon);
		menuItems.put(s, menuItem);
		deleteMenu.add(menuItem);
		add(deleteMenu);

		//JSeparator bottomSeparator = new JSeparator(SwingConstants.HORIZONTAL);
		//add(bottomSeparator);
		//separators.put("bottom", bottomSeparator);

		s = "Preview";
		menuItem = new NXMenuItem("Preview", s);
		menuItems.put(s, menuItem);
		add(menuItem);

		s = "TransferTo";
		NXTraverseMenu transferTo = new NXTraverseMenu("Transfer To", "", true);
		transferTo.setIcon(transferIcon);
		menuItems.put(s, transferTo);
		add(transferTo);

		s = "Transfer";
		String strTransfer;
		strTransfer = (local) ? "Upload" : "Download";
		menuItem = new NXMenuItem(strTransfer, s);
		menuItem.setIcon(transferIcon);
		menuItems.put(s, menuItem);
		add(menuItem);
	}

	public HashMap getIndex() {
		return menuItems;
	}

	public HashMap getSeparators() {
		return separators;
	}
}



